package com.aqie.easy.array;

import java.util.ArrayList;
import java.util.List;

/**
 * 119 返回杨辉三角第K行
 */
public class PascalsTriangleii {
    public List<Integer> getRow(int rowIndex) {
        List<List<Integer>> triangle = new ArrayList<>();
        if (rowIndex < 0) return new ArrayList<>();
        for (int i = 0; i <= rowIndex; i++){
            List<Integer> item = new ArrayList<>();
            for (int j = 0; j <= i; j++){
                if (j == 0 || j == i){
                    item.add(1);
                }else{
                    item.add(triangle.get(i-1).get(j-1) + triangle.get(i-1).get(j));
                }
            }
            triangle.add(item);
        }
        return triangle.get(rowIndex);
    }
}
